import numpy as np
from scipy import interpolate

def interpolate_data(data, factor=4):
    """
    将输入数据插值到原始数据量的factor倍，并保持整数
    
    参数:
        data: 原始数据 (numpy数组)
        factor: 插值倍数 (默认4)
        
    返回:
        插值后的数据 (numpy数组)
    """
    # 获取原始数据形状
    original_shape = data.shape
    
    # 对每行数据单独进行一维插值
    interpolated = np.zeros((original_shape[0], original_shape[1]*factor))
    
    for i in range(original_shape[0]):
        # 创建插值点
        x = np.arange(original_shape[1])
        
        # 创建插值函数
        interp_func = interpolate.interp1d(x, data[i,:], kind='linear')
        
        # 创建新的插值点
        new_x = np.linspace(0, original_shape[1]-1, original_shape[1]*factor)
        
        # 执行插值
        interpolated[i,:] = interp_func(new_x)
    
    # 四舍五入保持整数
    interpolated = np.round(interpolated).astype(int)
    
    return interpolated

# 示例使用
if __name__ == "__main__":
    # 示例数据 - 替换为你的实际数据
    example_data = np.array([
        [3, 1, 4, 30, 6],
        [1, 1, 0, 30, 1],
        [6, 7, 6, 30, 5]
    ])
    
    # 执行插值
    result = interpolate_data(example_data)
    print("原始数据:")
    print(example_data)
    print("\n插值后数据(4倍):")
    print(result)